package com.weirong.smartvault.dao;

import java.util.List;
import java.util.Set;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import com.weirong.smartvault.entity.CashboxRealtime;
import com.weirong.smartvault.entity.Stock;

@Repository
@Qualifier("stockRepository")
public interface StockRepository extends JpaRepository<Stock, Integer> {

    @Query("SELECT stock FROM Stock stock WHERE stock.box.typeCode = :typeCode and stock.box.denominationValue = :denominationValue")
    public List<Stock> getStockDetailByConditions(@Param("typeCode") String typeCode, @Param("denominationValue") Integer denominationValue);
	
	public List<Stock> findStockByBox(CashboxRealtime box);

    @Query("SELECT stock FROM Stock stock WHERE stock.box.typeCode in (:typeCodes)")
    public List<Stock> getStockByTypeCodes(@Param("typeCodes") Set<String> typeCodes);


    @Query("select s.box.typeCode as type_code, s.box.denominationValue as denomination_value, SUM(s.amount) as amount from Stock s group by s.box.typeCode, s.box.denominationValue")
    public List<?> getCurrentStocks();
}
